home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Grafik / Misc / ImageEnginer / ARexx / Batch / Shear.ieb < prev    next >
Encoding:
Text File  |  1997-02-02  |  5.3 KB  |  235 lines

  1. /*
  2. ** $VER: Shear.ieb 1.31, IE Arexx script
  3. ** Image Engineer Batch Processing script
  4. ** Copyright © by Patrik M Nydensten
  5. ** 2/2 1997 Stockholm/Sweden
  6. **
  7. ** Shear image.
  8. */
  9.  
  10. options results
  11. signal on error
  12.  
  13. parse arg input command
  14. input = upper(strip(input))
  15. address 'IMAGEENGINEER'
  16.  
  17. select  /* Required batch script commands */
  18.   when input = 'INFO' then    return get_info()
  19.   when input = 'CONFIG' then  return get_config(command)
  20.   when input = 'PROCESS' then return process_image(command)
  21.   otherwise do
  22.     'REQUEST' '"Failure in call to batch script!"' '" Quit "'
  23.     return '<ERROR>'
  24.   end
  25. end
  26.  
  27. exit 0
  28.  
  29. /* Required "Get_info" procedure  ------------------------------------ */
  30. /* S = SECONDARY, A = ALPHA, 1 = Single file, 2 = Multiple files       */
  31.  
  32. get_info:
  33.   back = 'OK'
  34. return back
  35.  
  36. /* Required "Get_config" procedure  ---------------------------------- */
  37.  
  38. get_config:
  39.   parse arg '"'command'"'
  40.  
  41.   Xoff=100 ; Yoff=100
  42.  
  43.   if command ~= '' then parse var command Xoff Yoff '#'CropQ '#'CalcType
  44.  
  45.   'IE_TO_FRONT'
  46.  
  47.   form = 'FORM "Shear" "Ok|Cancel "',
  48.   ' INTEGER,"X Amount",-4096,4096,'Xoff',SLIDER',
  49.   ' INTEGER,"Y Amount",-4096,4096,'Yoff',SLIDER'
  50.  
  51.   if command = '' then do
  52.     form = form||' CHECKBOX,"Crop image to original size?",0',
  53.     ' CYCLE,"Type:","Best|Fast",0'
  54.  
  55.     form
  56.     parse var result ok Xoff Yoff CropQ CalcType .
  57.     if ok = 0 then return '<ERROR>'
  58.  
  59.     if CalcType=0 then CalcType='BEST'
  60.     else CalcType = 'FAST'
  61.   end
  62.   else do
  63.     form
  64.     parse var result ok Xoff Yoff .
  65.     if ok = 0 then return '<ERROR>'
  66.  
  67.     CropQ = 'none'
  68.     CalcType = 'none'
  69.   end
  70.  
  71.   back = Xoff Yoff '#'CropQ '#'CalcType
  72. return back
  73.  
  74. /* Required "Process_image" procedure  ------------------------------- */
  75.  
  76. process_image:
  77.   parse arg '"'src_image'"' '"'dst_image'"' '"'options'"'
  78.   parse var options Xoff Yoff '#'CropQ '#'CalcType .
  79.  
  80.   'OPEN' '"'src_image'"' '24'
  81.   if (RC ~= 0) then do
  82.     'IE_TO_FRONT'
  83.     'REQUEST' '"Failed to load image:' d2c(10)||src_image'"' '" OK "'
  84.     return '<ERROR>'
  85.   end
  86.   else LoadImage = result
  87.  
  88. /* X shearing ------------------------------ */
  89.  
  90.   'PROJECT_INFO' LoadImage 'WIDTH'    /* Get width of image */
  91.   IW = RESULT
  92.   'PROJECT_INFO' LoadImage 'HEIGHT'    /* Get height of image */
  93.   IH = RESULT
  94.  
  95.   if CropQ = 0 then do
  96.     'RESIZE' LoadImage (IW+abs(Xoff)*2) IH 'CENTER'
  97.     NewImage = Result
  98.     'CLOSE' LoadImage
  99.     LoadImage = NewImage
  100.   end
  101.  
  102.   if Xoff ~= 0 then do
  103.     'OPEN' '"IE:Alpha/Gradient.alpha"' '8BIT'
  104.     GradientImage = Result
  105.  
  106.     'ROTATE' GradientImage 90 'FAST'
  107.     RotatedImage = Result
  108.     'CLOSE' GradientImage
  109.  
  110.     'SCALE' RotatedImage (IW+abs(Xoff)*2) IH 'BEST'
  111.     XAlphaImage = Result
  112.     'CLOSE' RotatedImage
  113.   end
  114.  
  115.   do while (Xoff ~= 0)
  116.  
  117.     if Xoff > 0 then do
  118.       if Xoff > 127 then do
  119.         XD = 127 ; Xoff = Xoff - XD
  120.       end
  121.       else do
  122.         XD = Xoff ; Xoff = Xoff - XD
  123.       end
  124.     end
  125.     else do
  126.       if Xoff < -127 then do
  127.         XD = -127 ; Xoff = Xoff - XD
  128.       end
  129.       else do
  130.         XD = Xoff ; Xoff = Xoff - XD
  131.       end
  132.     end
  133.  
  134.     'MARK' XAlphaImage 'ALPHA'
  135.     'MARK' LoadImage 'PRIMARY'
  136.  
  137.     'DISPLACE' XD 0 CalcType
  138.     NewImage = result
  139.     'CLOSE' LoadImage
  140.     LoadImage = NewImage
  141.  
  142.   end
  143.  
  144.   if XAlphaImage ~= 'XALPHAIMAGE' then 'CLOSE' XAlphaImage
  145.  
  146.  
  147. /* Y shearing ------------------------------ */
  148.  
  149.   'PROJECT_INFO' LoadImage 'WIDTH'    /* Get width of image */
  150.   IW = RESULT
  151.   'PROJECT_INFO' LoadImage 'HEIGHT'    /* Get height of image */
  152.   IH = RESULT
  153.  
  154.   if CropQ = 0 then do
  155.     'RESIZE' LoadImage IW (IH+abs(Yoff)*2) 'CENTER'
  156.     NewImage = Result
  157.     'CLOSE' LoadImage
  158.     LoadImage = NewImage
  159.   end
  160.  
  161.   if Yoff ~= 0 then do
  162.     'OPEN' '"IE:Alpha/Gradient.alpha"' '8BIT'
  163.     GradientImage = Result
  164.  
  165.     'SCALE' GradientImage IW (IH+abs(Yoff)*2) 'BEST'
  166.     YAlphaImage = Result
  167.     'CLOSE' GradientImage
  168.   end
  169.  
  170.   do while (Yoff ~= 0)
  171.  
  172.     if Yoff > 0 then do
  173.       if Yoff > 127 then do
  174.         YD = 127 ; Yoff = Yoff - YD
  175.       end
  176.       else do
  177.         YD = Yoff ; Yoff = Yoff - YD
  178.       end
  179.     end
  180.     else do
  181.       if Yoff < -127 then do
  182.         YD = -127 ; Yoff = Yoff - YD
  183.       end
  184.       else do
  185.         YD = Yoff ; Yoff = Yoff - YD
  186.       end
  187.     end
  188.  
  189.     'MARK' YAlphaImage 'ALPHA'
  190.     'MARK' LoadImage 'PRIMARY'
  191.  
  192.     'DISPLACE' 0 YD CalcType
  193.     NewImage = result
  194.     'CLOSE' LoadImage
  195.     LoadImage = NewImage
  196.  
  197.   end
  198.  
  199.   if YAlphaImage ~= 'YALPHAIMAGE' then 'CLOSE' YAlphaImage
  200.  
  201.   OutputImage = LoadImage
  202.  
  203.   if getclip('cfg_save_frmt')='' then setclip('cfg_save_frmt','ILBM CmpByteRun1')
  204.   'SAVE_DATA' OutputImage '"'dst_image'"' '"'getclip('cfg_save_frmt')'"'
  205.   if (RC ~= 0) then do
  206.     'IE_TO_FRONT'
  207.     'REQUEST' '"Failed to save image:' d2c(10)||dst_image'"' '" OK "'
  208.     return '<ERROR>'
  209.   end
  210.   'CLOSE' OutputImage
  211.  
  212.   back = 'OK'
  213. return back
  214.  
  215. /* Internal procedures  ---------------------------------------------- */
  216.  
  217. /*******************************************************************/
  218. /* This is where control goes when an error code is returned by IE */
  219. /* It puts up a message saying what happened and on which line     */
  220. /*******************************************************************/
  221.  
  222. error:
  223. if RC=5 then do
  224.     IE_TO_FRONT
  225.     LAST_ERROR
  226.     'REQUEST "'||RESULT||'"'
  227. end
  228. else do
  229.     IE_TO_FRONT
  230.     LAST_ERROR
  231.     'REQUEST "Error detected!!!'||D2C(10)||'Image Engineer error message is as follows'||D2C(10)||result||D2C(10)||'Script failed on line '||SIGL||'"' 'Doh!'
  232. end
  233.  
  234. return '<ERROR>'
  235.